package mysql

import (
	"disk/disk_rpc_server/disk_pb"
	"gorm.io/gorm"
)

func DiskListOrmToRpc(datalist []DiskList, resultList *[]*disk_pb.DiskList) {
	for _, disk := range datalist {
		// 创建一个DiskList消息实例
		diskList := &disk_pb.DiskList{
			Id:       int64(disk.ID),
			Name:     disk.Name,
			Level:    disk.Level,
			Email:    disk.Email,
			Phone:    disk.Phone,
			Birthday: disk.Birthday,
			Address:  disk.Address,
		}
		// 将DiskList消息实例添加到QueryResp的列表中
		*resultList = append(*resultList, diskList)
	}
}

func DiskListRpcToOrm(resultList []*disk_pb.DiskList, datalist *[]DiskList) {
	for _, val := range resultList {
		// 创建一个DiskList结构体实例
		diskList := DiskList{
			Model: gorm.Model{
				ID: uint(val.Id),
			},
			Name:     val.Name,
			Level:    val.Level,
			Email:    val.Email,
			Phone:    val.Phone,
			Birthday: val.Birthday,
			Address:  val.Address,
		}
		// 将DiskList结构体实例添加到切片中
		*datalist = append(*datalist, diskList)
	}
}
